package com.luych.toolbox.data.service.dao;

import com.luych.toolbox.common.enums.DataTransporterHistoryStatus;
import com.luych.toolbox.data.service.entity.DataTransporterHistory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface DataTransporterHistoryDao extends JpaRepository<DataTransporterHistory, String>, JpaSpecificationExecutor<DataTransporterHistory> {

    int countByDataSourceFromIdOrDataSourceToId(String dataSourceOneId, String dataSourceTwoId);

    int countByDataTransporterPlanId(String dataTransporterPlanId);

    Page<DataTransporterHistory> findByNameLike(String name, Pageable pageable);

    List<DataTransporterHistory> findByStatusIn(List<DataTransporterHistoryStatus> status);

    @Modifying
    @Query(value = "TRUNCATE data_transporter_history", nativeQuery = true)
    void truncate();

    long countByStartDateBetween(Date start, Date end);

    void deleteByIdIn(List<String> ids);

}